//
//  BaseViewController.m
//  滴滴快拍
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1];
}


- (void)saveData:(id)data DataName:(NSString *)DataName {
    // 沙盒路径
    //    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 1, YES) lastObject];
    // 创建一个文件管理器
    NSFileManager *manager = [NSFileManager defaultManager];
    // 拼接一个文件夹路径
    NSString *BagPath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
//    NSLog(@"%@", BagPath);
    // 创建文件夹
    [manager createDirectoryAtPath:BagPath withIntermediateDirectories:YES attributes:nil error:nil];
    //  存Data的文件路径
    NSString *DataFilePath = [BagPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.plist", DataName]];
    // 归档
    [NSKeyedArchiver archiveRootObject:data toFile:DataFilePath];
}



- (NSDictionary *)getDataWithDataName:(NSString *)dataName {
    // 沙盒路径 //NSHomeDirectory()
    //    NSString *sandBoxPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 1, YES) lastObject];
    // 拼接文件夹路径
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/MyCache"];
    // 文件名
    NSString *fileName = [NSString stringWithFormat:@"%@.plist",dataName];
    
    NSString *filePath = [path stringByAppendingPathComponent:fileName];
    
    NSDictionary *cacheDic = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
    
    return cacheDic;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
